package zmyutils;

import static java.lang.System.out;

import java.io.File;
import java.util.Set;

import org.apache.commons.lang.StringUtils;

import com.h819.core.commons.MyLangUtils;
import com.h819.core.file.excel.poi.POIUtils;

/**
 * @Title: Tools.java
 * @Description: TODO(个人用的一些常用工具)
 * @author H819
 * @date 2011-6-21
 * @version V1.0
 */
public class Tools {

	/**
	 * 从 gmail 通讯录中导出，是 cvs 格式，删除无用的列，使
	 */
	private void getGMailContact() {

		Set<String> lines = POIUtils.readExcel(new File("D:\\contacts.xls"));

		StringBuffer sf = new StringBuffer();

		for (String s : lines) {

			out.println(StringUtils.center("line ", 80, "*"));

			String firstName = (String) POIUtils.getColumValue(s, 0);
			String fix = (String) POIUtils.getColumValue(s, 2);
			String lastName = (String) POIUtils.getColumValue(s, 1);
			String mobile = (String) POIUtils.getColumValue(s, 3);

			String name = "";
			if (lastName != null)
				name = lastName;

			if (firstName != null)
				name = name + firstName;

			// if(mobile!=null)

			// out.println("Name :" +name);
			// out.println("mobile :" +StringUtils.substringBefore(mobile,
			// "."));
			// out.println("fix :"+ StringUtils.substringBefore(fix, "."));

			String stemp = "姓：	" + name + "\n";
			if (mobile != null)
				stemp = stemp
						+ "常用移动电话：	"
						+ StringUtils.remove(
								StringUtils.substringBefore(mobile, "."), "-")
						+ "\n";

			if (fix != null)
				stemp = stemp + "常用电话：	"
						+ StringUtils.substringBefore(fix, ".") + "\n";

			stemp = stemp + "\n";

			sf.append(stemp);

		}

		out.println(sf.toString());

	}

	/**
	 * 读取特定格式的首标网用户信息
	 */
	private void getCapitalContact() {

		Set<String> lines = POIUtils.readExcel(new File("D:\\fsf.xls"));

		StringBuffer sf = new StringBuffer();

		for (String s : lines) {

			out.println(StringUtils.center("line ", 80, "*"));

			String firstName = (String) POIUtils.getColumValue(s, 4);
			// String fix = (String) POIUtils.getColumValue(s, 2);
			String lastName = (String) POIUtils.getColumValue(s, 2);
			// String mobile = (String) POIUtils.getColumValue(s, 3);

			String name = "";

			if (firstName != null)
				name = firstName;
//			if (lastName != null)
//				name = name + "  "+lastName;

			//name = name + "\n";

			sf.append(name+"; ");

		}

		out.println(sf.toString());

	}
	
	/**
	 * 读取有换行的 excel 单元格
	 */
	private void excelLineBreak() {

		Set<String> lines = POIUtils.readExcel(new File("D:\\1.xls"));

		StringBuffer sf = new StringBuffer();

		String[] st = null;

		for (String s : lines) {

			out.println(StringUtils.center("line ", 80, "*"));

			String cell0 = (String) POIUtils.getColumValue(s, 0);
			String cell1 = (String) POIUtils.getColumValue(s, 1);

			// System.out.println("cell0=" + cell0 + " ; cell1=" + cell1);

			out.println(" ------------------ ");

			st = StringUtils.splitPreserveAllTokens(cell0,
					MyLangUtils.linebreak);
			for (String ss : st)
				out.print(ss + ";");

			out.println(" ------------------ ");
			
			st = StringUtils.splitPreserveAllTokens(cell1,
					utils.MyLangUtils2.linebreak);
			for (String ss : st)
				out.print(ss + ";");

		}
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

		Tools t = new Tools();
		t.getCapitalContact();

	}

}
